function formatparms(query){
    if(JSON.stringify(query) === "{}" ){
      return false
    }
    var keys = Object.keys(query)
    var arr=[];
    var value = []; 
    //用for进行遍历
    for (var i = 0,len = keys.length; i < len; i++) {
        var key = keys[i];
        value[i] = `'${query[key]}'`;
        arr.push(key+'='+ value[i])
    }
     
    return arr.join(' and ')
  }

//精确查询条件
exports.jointCondition = function (query,table){
       
        var query = formatparms(query)
      
        var queryString = 'select * from '+table
        if(query ){
         queryString = queryString+' where '+query
        } 
        return queryString
  }
  //模糊查询条件

 function  fuzzyformatparms(query){
    if(JSON.stringify(query) === "{}" ){
        return false
      }
      var keys = Object.keys(query)
      var arr=[];
      var value = []; 
      //用for进行遍历
      for (var i = 0,len = keys.length; i < len; i++) {
          var key = keys[i];
          value[i] = `${query[key]}`;
          
          arr.push(key+'  like ' + "'"+value[i]+"%'")
      }
       
      return arr.join(' and ')
 }
exports.jointFuzzyCondition = function (query,table){
  
    var query = fuzzyformatparms(query)
   
    var queryString = 'select * from '+table
    if(query ){
     queryString = queryString+" where "+query
    } 
   
    return queryString
}
//查询前n条数据  
exports.findNCondition = function (query,table,n){
        
    var query = formatparms(query)
    var queryString = 'select * from '+table 
    if(query ){
     queryString = queryString+' where '+query
    }else {
        //queryString = queryString+' where id in (select top '+n+' id from '+table+')'
        queryString = 'select top '+n+' DeptAccountID from '+table
    } 
    return queryString
}

//写入用户登录信息
exports.insertCondition = function (json,table){
    var keys = Object.keys(json).join(',')     
    var values = Object.values(json).join(',') 
    var queryString = 'INSERT INTO '+table +' ('+keys+')'+' VALUES '+'(' +values+')'
     console.log(queryString)
    return queryString
}